import { BaseWindow } from "../../../../../component/window/BaseWindow";
import { ILayer } from "../../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../../extend/language/Language";
import { ObjCreate } from "../../../common/ObjCreate";
import { GTextFormat } from "../../../../../common/GTextFormat";
import { FontUtil } from "../../../../../common/font/FontUtil";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { GuildRobCityCopyThreeResultRenderer } from "./GuildRobCityCopyThreeResultRenderer";
import { DataProvider } from "../../../../../../fl/data/DataProvider";
import { Cache } from "../../../../cache/Cache";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { SRobCityEndReward } from "../../../../../../Message/Public/SRobCityEndReward";
import { SRobCityThreeCopyInfo } from "../../../../../../Message/Public/SRobCityThreeCopyInfo";
import { EntityUtil } from "../../../../scene/layer/utils/EntityUtil";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
import { GTileList } from "../../../../../../com/mui/controls/GTileList";
import { GButton } from "../../../../../../com/mui/controls/GButton";
//class GuildRobCityCopyThreeResult
    
    export  class GuildRobCityCopyThreeResult extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(390, 350);
            this.titleHeight = 25;
            this.title = Language.getString(60951);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(18, 36, 354, 302, this);
            var loc1=new GTextFormat(FontUtil.stXingkaiName, 42, 16711935, true, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._resultText = ObjCreate.createGTextField("", 30, 45, 330, 60, this, loc1, false);
            ObjCreate.createBg(30, 95, 330, 2, this, ImagesConst.SplitLine);
            loc1 = new GTextFormat(FontUtil.songtiName, 12, GlobalStyle.color9Uint, true);
            ObjCreate.createGTextField(Language.getString(60968), 30, 100, 80, 20, this, loc1);
            ObjCreate.createGTextField(Language.getString(60969), 30, 120, 80, 20, this, loc1);
            this._mainGuild = ObjCreate.createGTextField("", 30, 100, 330, 20, this, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat4));
            this._guildLeader = ObjCreate.createGTextField("", 30, 120, 330, 20, this, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat4));
            ObjCreate.createBg(30, 155, 330, 2, this, ImagesConst.SplitLine);
            ObjCreate.createGTextField(Language.getString(60970), 30, 160, 200, 20, this, GlobalStyle.textFormat6);
            this._otherGuilds = ObjCreate.createTileList(30, 180, 330, 100, this);
            this._otherGuilds.rowHeight = 22;
            this._otherGuilds.columnWidth = 330;
            this._otherGuilds.verticalScrollPolicy = "off";
            this._otherGuilds.setStyle("cellRenderer", GuildRobCityCopyThreeResultRenderer);
            this._listDp = new DataProvider();
            this._otherGuilds.dataProvider = this._listDp;
            this._okBtn = ObjCreate.createGButton(Language.getString(62039), 165, 300, 60, 26, this);
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOkBtnClick);
            return;
        }

        /* internal  */onOkBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (Cache.instance.copy.isInCopy) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyLeaveWithoutComfirm));
            }
            this.hide();
            return;
        }

        public updateInfos(arg1: SRobCityEndReward, arg2: SRobCityThreeCopyInfo): void
        {
            var loc1=null;
            if (!arg1 || !arg2) 
            {
                return;
            }
            this._resultText.htmlText = this.isDefeated(arg1, arg2) ? Language.getString(60966) : Language.getString(60967);
            this._mainGuild.htmlText = "[" + EntityUtil.getProxyName(arg1.sEntityId) + "]" + arg1.guildName;
            this._guildLeader.htmlText = this.getLeadName(arg1, arg2);
            this._listDp.removeAll();
            var loc2=0;
            var loc3=arg2.robCityThreeJoinTeams;
            for(loc1 of loc3) 
            {
                if (EntityUtil.equal(loc1.sEntityId, arg1.sEntityId)) 
                {
                    continue;
                }
                this._listDp.addItem(loc1);
            }
            this._otherGuilds.dataProvider = this._listDp;
            return;
        }

        /* internal  */isDefeated(arg1: SRobCityEndReward, arg2: SRobCityThreeCopyInfo): Boolean
        {
            var loc1=null;
            var loc2=0;
            var loc3=arg2.robCityThreeJoinTeams;
            for(loc1 of loc3) 
            {
                if (!EntityUtil.equal(arg1.sEntityId, loc1.sEntityId)) 
                {
                    continue;
                }
                if (loc1.shaBak > 0) 
                {
                    return false;
                }
                return true;
            }
            return true;
        }

        /* internal  */getLeadName(arg1: SRobCityEndReward, arg2: SRobCityThreeCopyInfo): string
        {
            var loc1=null;
            var loc2=0;
            var loc3=arg2.robCityThreeJoinTeams;
            for(loc1 of loc3) 
            {
                if (!EntityUtil.equal(arg1.sEntityId, loc1.sEntityId)) 
                {
                    continue;
                }
                return loc1.leaderName;
            }
            return "";
        }

        /* internal */ /* var */_resultText: GTextFiled;

        /* internal */ /* var */_mainGuild: GTextFiled;

        /* internal */ /* var */_guildLeader: GTextFiled;

        /* internal */ /* var */_otherGuilds: GTileList;

        /* internal */ /* var */_listDp: DataProvider;

        /* internal */ /* var */_okBtn: GButton;
    }
